﻿using DevExpress.Xpf.Charts;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media;

namespace TeBigCommonUI.Items
{
    public abstract partial class BarChart : XYDiagramChartControl
    {
        public BarChart()
        {
            InitializeComponent();
        }

        protected override void OnInitChart()
        {
            InitChartInternal(chart, chart_diagram);
        }
    }

    public class Bar2DChart : BarChart
    {
        protected override Series CreateSeriesFromDataSource(IList<SeriesDataSource> source, int index)
        {
            return new BarSideBySideSeries2D()
            {
                Model = new BorderlessGradientBar2DModel(),
                BarWidth = source[index].BarWidth,
            };
        }
    }

    public class Bar3DChart : BarChart
    {
        protected override Series CreateSeriesFromDataSource(IList<SeriesDataSource> source, int index)
        {
            var series = new BarSideBySideSeries2D()
            {
                Model = new Quasi3DBar2DModel(),
                BarWidth = source[index].BarWidth,
                Label = new SeriesLabel
                {
                    ResolveOverlappingMode = ResolveOverlappingMode.JustifyAllAroundPoint
                }
            };

            return series;
        }
    }

    public class BarGlow2DChart : BarChart
    {
        protected override Series CreateSeriesFromDataSource(IList<SeriesDataSource> source, int index)
        {
            var model = Application.Current.Resources["myCustomBar2DModel"] as CustomBar2DModel;

            return new BarSideBySideSeries2D()
            {
                Model = model,
                BarWidth = source[index].BarWidth,
                ColorEach = true,
            };
        }
    }

    public class BarSharp2DChart : BarChart
    {
        protected override Series CreateSeriesFromDataSource(IList<SeriesDataSource> source, int index)
        {
            var model = Application.Current.Resources["myCustomBar2DModel2"] as CustomBar2DModel;

            return new BarSideBySideSeries2D()
            {
                Model = model,
                BarWidth = source[index].BarWidth,
                ColorEach = true,
            };
        }
    }

    public class BarRound2DChart : BarChart
    {
        protected override Series CreateSeriesFromDataSource(IList<SeriesDataSource> source, int index)
        {
            return new BarSideBySideSeries2D()
            {
                Model = new SteelColumnBar2DModel(),
                BarWidth = source[index].BarWidth,
            };
        }
    }

    public class BarStack2DChart : BarChart
    {
        protected override Series CreateSeriesFromDataSource(IList<SeriesDataSource> source, int index)
        {
            return new BarStackedSeries2D()
            {
                Model = new BorderlessGradientBar2DModel(),
                BarWidth = source[index].BarWidth,
            };
        }
    }

    public class BarStack3DChart : BarChart
    {
        protected override Series CreateSeriesFromDataSource(IList<SeriesDataSource> source, int index)
        {
            return new BarStackedSeries2D()
            {
                Model = new Quasi3DBar2DModel(),
                BarWidth = source[index].BarWidth,
            };
        }
    }

    public abstract class BarExtendChart : BarChart
    {
        protected abstract Series CreateBarSeries(IList<SeriesDataSource> source, int index);
        protected abstract Series CreateExtendSeries(IList<SeriesDataSource> source, int index);

        protected override Series CreateSeriesFromDataSource(IList<SeriesDataSource> source, int index)
        {
            if (index == 0)
            {
                return CreateBarSeries(source, index);
            }
            else
            {
                return CreateExtendSeries(source, index);
            }
        }
    }


    public class BarSteel2DWithLineChart : BarExtendChart
    {
        protected override Series CreateBarSeries(IList<SeriesDataSource> source, int index)
        {

            return new BarSideBySideSeries2D()
            {
                Model = new SteelColumnBar2DModel(),
                BarWidth = source[index].BarWidth,
            };
        }

        protected override Series CreateExtendSeries(IList<SeriesDataSource> source, int index)
        {

            return new LineSeries2D()
            {
                MarkerModel = new CircleMarker2DModel(),
                MarkerVisible = true,
            };
        }
    }

    public class Bar2DWithAreaChart : BarExtendChart
    {
        protected override Series CreateBarSeries(IList<SeriesDataSource> source, int index)
        {
            return new BarSideBySideSeries2D()
            {
                Model = new BorderlessGradientBar2DModel(),
                BarWidth = source[index].BarWidth,
            };
        }

        protected override Series CreateExtendSeries(IList<SeriesDataSource> source, int index)
        {
            return new SplineAreaSeries2D();
        }
    }

    public class Bar3DWithLineChart : BarExtendChart
    {
        protected override Series CreateBarSeries(IList<SeriesDataSource> source, int index)
        {

            return new BarSideBySideSeries2D()
            {
                Model = new Quasi3DBar2DModel(),
                BarWidth = source[index].BarWidth,
            };
        }

        protected override Series CreateExtendSeries(IList<SeriesDataSource> source, int index)
        {
            return new LineSeries2D()
            {
                MarkerModel = new CircleMarker2DModel(),
                MarkerVisible = true,
            };
        }
    }

    public class BarStack2DWithLineChart : BarExtendChart
    {
        protected override Series CreateBarSeries(IList<SeriesDataSource> source, int index)
        {

            return new BarStackedSeries2D()
            {
                Model = new BorderlessGradientBar2DModel(),
                BarWidth = source[index].BarWidth,
            };
        }

        protected override Series CreateExtendSeries(IList<SeriesDataSource> source, int index)
        {
            return new LineSeries2D()
            {
                MarkerModel = new CircleMarker2DModel(),
                MarkerVisible = true,
            };
        }
    }
}